﻿using MediatR;
using SmartMedicalCare.API.Write.Applications.Commands;
using SmartMedicalCare.Domain;
using SmartMedicalCare.ErronCode;
using SmartMedicalCare.Infrastructure.Implaction;

namespace SmartMedicalCare.API.Write.Applications.CommandHandlers
{
    public class DeleteHospitalCommandHandler : IRequestHandler<DeleteHospitalCommand, APIResult<int>>
    {
        private readonly IBaseRespository<HospitalModel> hospRep;

        public DeleteHospitalCommandHandler(IBaseRespository<HospitalModel> hospRep)
        {
            this.hospRep = hospRep;
        }

        public async Task<APIResult<int>> Handle(DeleteHospitalCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code=ResultCode.删除成功;
            result.Message=ResultCode.删除成功.ToString();

            var res = hospRep.GetAll().FirstOrDefault(x=>x.HospitalId==request.HospitalId);
            res.IsDeleted=true;
            await hospRep.UpdateAsync(res);

            return await Task.FromResult(result);
        }
    }
}
